
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../common/SharedPreferencesHelper.dart';
import '../common/routes.dart';

class AuthMiddleware extends GetMiddleware {

  @override
  RouteSettings? redirect(String? route) {
    // Check if the user is authenticated

    bool isAuthenticated = false; // This would be your logic
    var token = SharedPreferencesHelper.getString("token");
    if (token != null && token.isNotEmpty) {
      isAuthenticated = true;
    }

    if (!isAuthenticated) {
      // If the user is not authenticated, redirect to the login page
      return const RouteSettings(name: Routes.LOGIN);
    }

    // If the user is authenticated, allow the navigation
    return null;
  }

  @override
  GetPage? onPageCalled(GetPage? page) {
    debugPrint('Page called: ${page.toString()}');
    return super.onPageCalled(page);
  }
}